﻿@model List<Permission>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>系统权限管理</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
    @if (TempData["Message"] != null)
    {
        <script>alert('@Html.Raw(TempData["Message"])');</script>
    }

    <div class="container mt-5">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header bg-primary text-white">
                        系统权限管理
                    </div>
                    <div class="card-body">
                        <table class="table table-striped">
                            <thead class="bg-primary text-white">
                                <tr>
                                    <th>权限ID</th>
                                    <th>权限名称</th>
                                    <th>权限描述</th>
                                    <th>相关资源</th>
                                    <th>相关操作</th>
                                    <th>所属域或模块</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in Model)
                                {
                                    <tr>
                                        <td>@item.permission_id</td>
                                        <td>@item.permission_name</td>
                                        <td>@item.description</td>
                                        <td>@item.resource</td>
                                        <td>@item.action</td>
                                        <td>@item.domain</td>
                                        <td>
                                            <button class="btn btn-sm btn-primary" 
                                                    data-toggle="modal" 
                                                    data-target="#editPermissionModal" 
                                                    data-permission_id="@item.permission_id" 
                                                    data-permission_name="@item.permission_name"
                                                    data-description="@item.description"
                                                    data-resource="@item.resource"
                                                    data-action="@item.action"
                                                    data-domain="@item.domain">
                                                编辑
                                            </button>
                                        </td>
                                        <td>
                                            <form asp-action="DelSumbit1" asp-controller="UserAndRole" method="post" >
                                                <input type="hidden" name="permission_id" value="@item.permission_id" />
                                                <input type="submit" class="btn btn-danger delete-btn" value="删除">
                                            </form>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                        <div class="text-center">
                            <a asp-controller="UserAndRole" asp-action="AddPermission" class="btn btn-primary my-auto" id="AddButton">新增</a>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 修改系统权限的模态窗口 -->
    <div class="modal fade" id="editPermissionModal" tabindex="-1" role="dialog" aria-labelledby="editPermissionModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header bg-primary text-white">
                    <h5 class="modal-title" id="editPermissionModalLabel">修改系统权限</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>

                <div class="modal-body">
                    <form asp-controller="UserAndRole" asp-action="UpdatePermissionSumbit" method="post">
                        <input type="hidden" id="editpermissionId" name="permission_id" value="">
                        <div class="form-group">
                            <label for="editpermission_Name">权限名称</label>
                            <input type="text" class="form-control" id="editpermission_Name" name="permission_name" required>
                        </div>

                        <div class="form-group">
                            <label for="editdescription">权限描述</label>
                            <input type="text" class="form-control" id="editdescription" name="description" required>
                        </div>

                        <div class="form-group">
                            <label for="editresource">相关资源</label>
                            <input type="text" class="form-control" id="editresource" name="resource" required>
                        </div>

                        <div class="form-group">
                            <label for="editaction">相关操作</label>
                            <input type="text" class="form-control" id="editaction" name="action" required>
                        </div>

                        <div class="form-group">
                            <label for="editdomain">所属域或模块</label>
                            <input type="text" class="form-control" id="editdomain" name="domain" required>
                        </div>

                        <div class="text-center">
                            <input type="submit" class="btn btn-primary" value="保存更改" />
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>

    <script>
        $('#editPermissionModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var permission_Id = button.data('permission_id');
            var permission_Name = button.data('permission_name');
            var Description = button.data('description');
            var Resource = button.data('resource');
            var Action = button.data('action');
            var Domain = button.data('domain');

            var modal = $(this);
            modal.find('#editpermissionId').val(permission_Id);
            modal.find('#editpermission_Name').val(permission_Name);
            modal.find('#editdescription').val(Description);
            modal.find('#editresource').val(Resource);
            modal.find('#editaction').val(Action);
            modal.find('#editdomain').val(Domain);
        });
    </script>



</body>
</html>





